package dao

import (
	"gitee.com/cyanbleeze/go-image-management/internal/model"
	"gitee.com/cyanbleeze/go-image-management/pkg/app"
)

func (d *Dao) CreateFavoritePicture(fID uint, pID uint) error {
	fp := model.FavoritePicture{
		FavoriteID: fID,
		PictureID:  pID,
	}
	return fp.Create(d.engine)
}

func (d *Dao) UpdateFavoritePicture(id uint, fID uint) error {
	fp := model.FavoritePicture{
		FavoriteID: fID,
	}
	fp.ID = id
	return fp.Update(d.engine)
}

func (d *Dao) DeleteFavoritePicture(id uint) error {
	fp := model.FavoritePicture{}
	fp.ID = id
	return fp.Delete(d.engine)
}

func (d *Dao) GetFavoritePicture(id uint) (*model.FavoritePicture, error) {
	fp := model.FavoritePicture{}
	fp.ID = id
	return fp.Get(d.engine)
}

func (d *Dao) GetFavoriteListPictureByFID(fID uint, page int, pageSize int) ([]*model.FavoritePicture, error) {
	fp := model.FavoritePicture{
		FavoriteID: fID,
	}
	return fp.List(d.engine, app.GetPageOffset(page, pageSize), pageSize)
}

func (d *Dao) CountFavoritePictureListByFID(fID uint) (int, error) {
	fp := model.FavoritePicture{
		FavoriteID: fID,
	}
	return fp.Count(d.engine)
}

func (d *Dao) CountFavoritePictureListByPID(pID uint) (int, error) {
	fp := model.FavoritePicture{
		PictureID: pID,
	}
	return fp.Count(d.engine)
}
